Creating a package.json file 您所在的位置:网站首页 package default Creating a package.json file

Creating a package.json file

2023-05-11 11:55| 来源: 网络整理| 查看: 265

You can add a package.json file to your package to make it easy for others to manage and install. Packages published to the registry must contain a package.json file.

A package.json file:

lists the packages your project depends onspecifies versions of a package that your project can use using semantic versioning rulesmakes your build reproducible, and therefore easier to share with other developers

Note: To make your package easier to find on the npm website, we recommend including a custom description in your package.json file.

package.json fieldsRequired name and version fields

A package.json file must contain "name" and "version" fields.

The "name" field contains your package's name, and must be lowercase and one word, and may contain hyphens and underscores.

The "version" field must be in the form x.x.x and follow the semantic versioning guidelines.

Author field

If you want to include package author information in "author" field, use the following format (email and website are both optional):

聽Your Name (http://example.com)Example聽{ "name": "my-awesome-package", "version": "1.0.0", "author": "Your Name "}Creating a new package.json file

You can create a package.json file by running a CLI questionnaire or creating a default package.json file.

Running a CLI questionnaire

To create a package.json file with values that you supply, use the npm init command.

On the command line, navigate to the root directory of your package.

聽cd /path/to/package

Run the following command:

聽npm init

Answer the questions in the command line questionnaire.

Customizing the package.json questionnaire

If you expect to create many package.json files, you can customize the questions asked and fields created during the init process so all the package.json files contain a standard set of information.

In your home directory, create a file called .npm-init.js.

To add custom questions, using a text editor, add questions with the prompt function:



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有